package com.common.domainService;

import java.util.List;

import javax.mail.internet.AddressException;

import org.apache.log4j.Logger;

import com.applicationLayer.utility.EmailSender;
import com.common.DAO.ICovoitureurDAO;

public class NewsLetterService implements INewsLetterService {

	Logger logger = Logger.getLogger(NewsLetterService.class);
	private  ICovoitureurDAO covoitureurDAO;
	
	


	@Override
	public int SendNewsLetter(String newsLetterObject, String content) throws AddressException {
		List<String> userList=this.getCovoitureurDAO().findNewsLetterReceiver();
		EmailSender emailSender=new EmailSender(false);
		if(userList.size()>0){
			try{
				emailSender.sendClassicEmail(userList,newsLetterObject , content);
			}catch (Exception e) {
				return -1;
			}
		}
		return userList.size();
	}




	/**
	 * @return the covoitureurDAO
	 */
	public ICovoitureurDAO getCovoitureurDAO() {
		return covoitureurDAO;
	}




	/**
	 * @param covoitureurDAO the covoitureurDAO to set
	 */
	public void setCovoitureurDAO(ICovoitureurDAO covoitureurDAO) {
		this.covoitureurDAO = covoitureurDAO;
	}
}
